package sv.view;

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import sv.main.*;
//import sv.net.*;
import sv.net2.NetConnection;

public class MouseBattleAdapter extends MouseAdapter {
	
	private MyNetwork connection;
	private Game game;
	private JTextArea log;
	
	public MouseBattleAdapter(MyNetwork connection, Game oGame, JTextArea oLog){
		super();
		this.connection = connection;
		game = oGame;
		log = oLog;
	}
	
	public void mouseEntered(MouseEvent event){
		Tile source = (Tile)event.getSource();
		source.setHover(Color.orange);
	}
	
	public void mouseExited(MouseEvent event){
		Tile source = (Tile)event.getSource();
		source.removeHover();
	}
	
	public void mouseClicked(MouseEvent event){
		Tile source = (Tile)event.getSource();
		int number;
		if (game.getShots() < 3){
			if (game.iLost()){
				log.append("you are defeated\n");
			}
			else{
				number = source.X()+10*source.Y();
				if (game.areAllReady()){
					connection.connection().sendShoot((byte)number);
					game.incShots();
				}
			}
		}
		else {
			log.append("opponent is not ready yet\n");
		}
	}

}
